package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.LbsTerminalState;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.LbsTerminalStateDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-08-08 09:47:28
 */
public class LbsTerminalStateConverts {

    private static Logger LOG = LoggerFactory.getLogger(LbsTerminalStateConverts.class);

    public static List<LbsTerminalStateDTO> convert(List<LbsTerminalState> lbsTerminalStateList) {
        if (CollectionUtils.isEmpty(lbsTerminalStateList)) {
            return Collections.EMPTY_LIST;
        }

        List<LbsTerminalStateDTO> lbsTerminalStateListResult = Lists.newArrayList();
        for (LbsTerminalState lbsTerminalState : lbsTerminalStateList) {
            lbsTerminalStateListResult.add(convert(lbsTerminalState));
        }
        return lbsTerminalStateListResult;
    }

    public static LbsTerminalStateDTO convert(LbsTerminalState lbsTerminalState) {
        try {
            return BeanUtils.copy(lbsTerminalState, LbsTerminalStateDTO.class);
        } catch (Exception e) {
            LOG.error("LbsTerminalState到LbsTerminalStateDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "LbsTerminalState到LbsTerminalStateDTO转换失败", e);
        }
    }

    public static LbsTerminalState convert(LbsTerminalStateDTO lbsTerminalStateDTO) {
        try {
            return BeanUtils.copy(lbsTerminalStateDTO, LbsTerminalState.class);
        } catch (Exception e) {
            LOG.error("LbsTerminalStateDTO到LbsTerminalState转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "LbsTerminalStateDTO到LbsTerminalState转换失败", e);
        }
    }
}